package com.book.controller;


import com.book.pojo.Book;
import com.book.result.Result;
import com.book.service.BookService;
import com.book.vo.BookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/book")
public class BookController {

    @Autowired
    private BookService bookService;

    //作者创作作品
    @PostMapping("insertBook")
    public Result  insertBook(@RequestBody Book book){
        bookService.insertBook(book);
        return Result.OK();
    }

    //作者修改作品
    @PutMapping("updateBook")
    public Result updateBook(@RequestBody Book book){
        bookService.updateBook(book);
        return Result.OK();
    }

    //删除作品就得删除全部章节和章节信息
    @DeleteMapping("deleteBook")
    public Result deleteBook(@RequestParam Long id){
        bookService.deleteBook(id);
        return Result.OK();
    }

    //根据bookid查询作品章节目录
    @GetMapping("getChapterByBookId")
    public Result getChapterByBookId(@RequestParam Long id){
        BookVo bookVo = bookService.getChapterByBookId(id);
        return Result.OK().setData(bookVo);
    }


}
